package com.mytomcat.catalina.handler;

import com.mytomcat.catalina.adapter.CoyoteAdapter;
import com.mytomcat.catalina.connector.Connector;
import java.io.IOException;
import java.net.Socket;

/**
 * 连接handler
 *
 * @author supu
 * @date 2019-04-22 15:35
 **/
public class ConnectionHandler implements Handler,Runnable {
    private Socket socket;
    private Connector connector;

    public ConnectionHandler(Socket socket,Connector connector) {
        this.socket = socket;
        this.connector = connector;
    }

    @Override
    public void process() {
        CoyoteAdapter adapter = new CoyoteAdapter(connector);
        adapter.service(socket);
    }

    @Override
    public void run() {
        process();

        try {
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
